import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;

public class LabeledRectangle extends Rectangle implements Comparable<LabeledRectangle> {

	private Color color;
	private String text;
	int level;
	boolean drawn;
	public LabeledRectangle left, right;
	
	public LabeledRectangle (int x, int y, int width, int height, Color c, String s)
	{
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.color = c;		
		this.text = s;
		this.drawn = false;
		this.left = null;
		this.right = null;
	}
	
	public void setColor (Color c)
	{
		color = c;
	}
	
	public Color getColor ()
	{
		return color;
	}
	
	public String getText()
	{
		return text;
	}
	
	public String toString()
	{
		return text;
	}
	
	public void setText(String t)
	{
		this.text = t;
	}

	public void draw (Graphics g)
	{
		Font font = new Font("Dialog", Font.PLAIN, 18); 
		FontMetrics metrics = new FontMetrics(font) {  };
	    Rectangle2D bounds = metrics.getStringBounds(text, null);  
		int stringWidth = (int)bounds.getWidth();
		int stringHeight = (int)bounds.getHeight();
		
		g.setFont(font);
	
		g.setColor(color);	
		g.fillRect(x, y, width, height);
		
		g.setColor(Color.white);
		g.drawString(text, x + ((width - stringWidth)/2), y + ((height + stringHeight/2)/2));
		
	}
	
	public void drawLines (Graphics g)
	{
		g.setColor(Color.black);
		
		if (this.left != null)
		{			
			g.drawLine((int)this.getCenterX(), (int)this.getCenterY(), (int)left.getCenterX(), (int)left.getCenterY());			
		}
		
		if (this.right != null)
		{			
			g.drawLine((int)this.getCenterX(), (int)this.getCenterY(), (int)right.getCenterX(), (int)right.getCenterY());			
		}	
	}

	public int compareTo(LabeledRectangle lr) {
		
		Integer A = Integer.parseInt(text);
		Integer B = Integer.parseInt(lr.getText());
	
		return A.compareTo(B);
		
	}
	
}
